//
//  UserViewController.m
//  FKGW
//
//  Created by song ce on 2017/2/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "UserViewController.h"

@interface UserViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userLabel;
@property (strong, nonatomic) IBOutlet UIView *doneButton;

@end

@implementation UserViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    if(!ISNOTNEEDMESSAGEBTN){
        self.isNeedMessageItem = YES;
    }

    self.userLabel.text = USERNAME;
//    [self initRightBarItem];
}

- (void)initRightBarItem{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame=CGRectMake(0, 0, 20, 40);
    [rightButton setImage:[UIImage imageNamed:@"nav_xinxi_nor"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    self.rightItem =rightButton;
}

- (IBAction)doneAction:(UIButton *)sender {
    if(!self.userLabel.text.length){
        [MBProgressHUD showTipMessageInWindow:@"请输入用户名"];
        return;
    }
    
    //修改用户名接口
    NSDictionary *paramDic = @{@"userId":USERID,
                               @"nickName":self.userLabel.text};
    __weak typeof(self)  weakSelf = self;
    [Tools AFNetworkingRequestTypePostWithUrl:CHANGNIKENAME paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"修改用户名接口--%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSDictionary *dataDic = resultDic[@"data"];
            if([dataDic isKindOfClass:[NSNull class]]){
                return ;
            }
            if([dataDic[@"status"] isEqualToString:@"true"]){
                [MBProgressHUD showTipMessageInWindow:@"用户名修改成功"];
                [weakSelf performSelector:@selector(popToSettingVc) withObject:nil afterDelay:1];
            }else{
                if(dataDic[@"errorString"]){
                    [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                }
            }
        }else{
            if(resultDic[@"errorString"]){
                [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
            }
        }
    }];
}

-(void)popToSettingVc{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
